<template>
	<base-page class="base-form" title="签到二维码" @back="onCancel()">
	<view>
		<view style="text-align: center;margin-top:50px;">
			<view style="font-size: 20px;">{{defaultData.title}} 课程签到二维码</view>
			<view style="margin-top:10px;">{{defaultData.attendClassTime}}</view>
			<view style="margin-top: 10px;">{{defaultData.quittingTime}}</view>
			<view style="margin-top: 10px;">{{defaultData.title}}</view>
			<view style="margin-top: 10px;">{{defaultData.professorName}}</view>
			<image :src="signInCode" style="width: 320px;height: 320px;"></image>
			<view style="margin-top:10px;color: blue;" @click="createQrCode"><uni-icons type="reload"
					style="color: blue;" size="20"></uni-icons>点击刷新二维码</view>
		</view>
	</view>
</base-page>
</template>
<script>

	import {
		CourseInfoController
	} from "@/api";
	export default {
		data() {
			return {
				defaultData: {},
				signInCode: '',
				timer: null
			}
		},
		onLoad(val) {
			this.defaultData = JSON.parse(decodeURIComponent(val.data));
			console.log(this.defaultData);
			
		},
		mounted() {
			this.createQrCode()
			this.timer = setInterval(() => {
				this.createQrCode()
			}, 10000) // 10s
		},
		onUnload() {
			if (this.timer) {
				clearTimeout(this.timer);
				this.timer = null;
			}
		},
		methods: {
			onCancel() {
				uni.navigateBack();
			},
			createQrCode() {
				let data = {
					classId: this.defaultData.classId,
					courseId: this.defaultData.id
				}

				const params = {
					studentSignInDto: {
						classId: this.defaultData.classId,
						courseId: this.defaultData.id
					},
				};

				CourseInfoController.QRcodecreate(this, params)
					.then((res) => {
						if (res) {
							this.signInCode = res
						} else {
							console.log("系统错误")
						}
					})
					.catch((e) => {});
				// getQRCode(data).then((res) => {
				// 	if (res.code == 200) {
				// 		this.signInCode = res.msg
				// 	} else {
				// 		console.log("系统错误")
				// 	}
				// })
			}
		}
	}
</script>

<style>

</style>